<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>用户添加</title>
<link rel="stylesheet" href="../layui/css/layui.css">
<link rel="stylesheet" href="../layer/theme/default/layer.css">
<script type="text/javascript" src="../layer/layer.js"></script>
<script type="text/javascript" src="../js/jquery-3.3.1.js"></script>
<script src="../layui/layui.all.js"></script>
<script src="../layer/mobile/layer.js"></script>

</head>
<body>
<div style="padding:60px;">
<form class="layui-form layui-form-pane" >
  <div class="layui-form-item">
    <label class="layui-form-label">邮箱地址：</label>
    <div class="layui-input-inline">
      <input type="text" name="email" lay-verify="required" placeholder="输入邮箱，用于登陆" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">密码：</label>
    <div class="layui-input-inline">
      <input type="text" name="pwd" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">重复密码：</label>
    <div class="layui-input-inline">
      <input type="text" name="pwd2" lay-verify="required" placeholder="请重新输入密码" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">输入昵称：</label>
    <div class="layui-input-inline">
      <input type="text" id="name" name="name" lay-verify="required" placeholder="请输入昵称" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <button style="margin:15px;margin-left:40px;" type="button" id="btn1" class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo2">添加用户</button>
    <button type="button" style="margin:15px;" id="btn2" class="layui-btn">返回首页</button>
  </div>
</form>
</div>
<script>
$(function(){
	$("button#btn1").click(function(){

		if($("#name").val()==null||$("#name").val()==''||$("#name").val()==undefined ){
			alert("输入有空！");
		}else{
			$.post("ljx.useradd",$("form").serialize(),function(data){
				var c = JSON.parse(data);
				if(c.code==0000){
					alert("添加成功!");
					setTimeout(() => {
						location.href="usermanage.html";
					}, 800);
					
				}else if(c.code==0001){
					alert("添加失败！该邮箱已注册")
				}else if(c.code==0002){
					alert("添加失败！");
				}else{
					alert("两次密码输入不正确");
				}
			})
		}
		
	})
	$("button#btn2").click(function(){
		location.href="usermanage.html";
	})
})
</script>
</body>
</html>        
                